<extend name="Common@Base/layout"/>
<block name="body">
    <include file="Public/setleft"/>
    <div class="pside-toggle pside-hide"><i class="fa fa-angle-double-left"></i></div>
    <form id="paging_form" name="paging_form" method="post" action="/set/user/index">
        <div class="pmain">
            <div class="main-content main-pagebar-content">
                <div class="container-fluid">
                    <div class="row">
                        <div class="col-sm-12">
                            <h3 class="mod-title">
                                <span class="t">用户管理</span>
                            </h3>
                            <div class="panel panel-default">
                                <div class="panel-body panel-body-up-table">
                                    <div class="search-panel">
                                        <div class="search">
                                            <div class="dropdown btn-group">
                                                <a class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                                    <span id="search_status_name" class="option-name">状态</span> <i class="fa fa-angle-down"></i></a>
                                                <ul class="dropdown-menu dropdown-option-menu">
                                                    <li><a data-value="" role="button">全部</a></li>
                                                    <li><a data-value="0" role="button">停用</a></li>
                                                    <li><a data-value="1" role="button">启用</a></li>
                                                </ul>
                                                <input id="search_status" name="search_status" class="option-value filter-item-value" type="hidden"
                                                       value="{$_page->parameter['search_status']}">
                                            </div>

                                            <div class="dropdown btn-group">
                                                <a class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                                    <span id="rank_name" name="rank_name" class="option-name">级别</span> <i class="fa fa-angle-down"></i>
                                                </a>
                                                <ul class="dropdown-menu dropdown-option-menu">
                                                    <li><a data-value="" role="button">全部</a></li>
                                                    <li><a data-value="1" role="button">省级</a></li>
                                                    <li><a data-value="2" role="button">市级</a></li>
                                                    <li><a data-value="3" role="button">区级</a></li>
                                                </ul>
                                                <input id="rank" name="rank" class="option-value filter-item-value" type="hidden" value="{$_page->parameter['rank']}">
                                            </div>

                                            <div class="dropdown btn-group">
                                                <a class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                                    <span id="attribute_name" name="attribute_name" class="option-name">属性</span> <i class="fa fa-angle-down"></i>
                                                </a>
                                                <ul class="dropdown-menu dropdown-option-menu">
                                                    <li><a data-value="" role="button">全部</a></li>
                                                    <li><a data-value="1" role="button">单位</a></li>
                                                    <li><a data-value="2" role="button">学校</a></li>
                                                    <li><a data-value="3" role="button">社区</a></li>
                                                </ul>
                                                <input id="attribute" name="attribute" class="option-value filter-item-value" type="hidden" value="{$_page->parameter['attribute']}">
                                            </div>

                                            <div class="btn-group">
                                                <input name="search_key" type="text" class="form-control" value="{$_page->parameter['search_key']|urldecode}"
                                                       placeholder="请输入标题">
                                            </div>
                                            <div class="btn-group">
                                                <button type="submit">搜索</button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="table-responsive">
                                    <table class="table-check table-link-hover table table-striped table-bordered table-hover">
                                        <thead>
                                        <tr>
                                            <th style="width:40%">单位全称</th>
                                            <th>联系人</th>
                                            <th>联系电话</th>
                                            <th style="width:8%">类型</th>
                                            <th style="width:8%">时间</th>
                                            <th style="width:6%">级别</th>
                                            <th style="width:6%">属性</th>
                                            <th style="width:6%">状态</th>
                                            <th style="width:8%" class="td-action">操作</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <volist name="user_list" id="user">
                                            <tr data-vid="{$user.id}"
                                                data-account="{$user.account}"
                                                data-contact="{$user.contact}"
                                                data-contact_phone="{$user.contact_phone}"
                                                data-email="{$user.email}"
                                                data-rank="{$user.rank}"
                                                data-attribute="{$user.attribute}"
                                                >
                                                <td>{$user.account}</td>
                                                <td>{$user.contact}</td>
                                                <td>{$user.contact_phone}</td>
                                                <td>{$user.role|fc_get_config_value="USER_ROLE"}</td>
                                                <td>{$user.create_at|fc_get_date}</td>
                                                <td>{$user.rank|fc_get_config_value="TASK_RANK"}</td>
                                                <td>{$user.attribute|fc_get_config_value="USER_ATTRIBUTE"}</td>
                                                <if condition="$user['status']==0">
                                                    <td style="color: red">
                                                        {$user.status|fc_get_config_value="USER_STATUS"}
                                                    </td>
                                                    <else/>
                                                    <td>
                                                        {$user.status|fc_get_config_value="USER_STATUS"}
                                                    </td>
                                                </if>

                                                <td class="td-action">
                                                    <a class="td-btn" data-toggle="modal" data-target="#edit-user" data-type="edit-info" role="button">编辑</a>
                                                    <if condition="$user['status']==0">
                                                        <a class="td-btn" data-type="edit-status" data-status="1" role="button">启用</a>
                                                        <else/>
                                                        <a class="td-btn" data-type="edit-status" data-status="0" role="button">停用</a>
                                                    </if>
                                                    <a class="td-btn" data-type="delete-status" role="button">删除</a>
                                                </td>
                                            </tr>
                                        </volist>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="main-pagebar">
                <include file="Common@Public/paging"/>
            </div>
        </div>
    </form>

    <include file="edit"/>

    <script>
        $(document).ready(function () {
            $('#nav-set').addClass("active");
            var vx = $("#search_status").val();
            if (vx != "") {
                $("#search_status").prev().find('a').each(function () {
                    var $this = $(this);
                    if ($this.data('value') == vx) {
                        $("#search_status_name").text($this.text());
                    }
                });
            }

            vx = $("#rank").val();
            if (vx != "") {
                $("#rank").prev().find('a').each(function () {
                    var $this = $(this);
                    if ($this.data('value') == vx) {
                        $("#rank_name").text($this.text());
                    }
                });
            }

            vx = $("#attribute").val();
            if (vx != "") {
                $("#attribute").prev().find('a').each(function () {
                    var $this = $(this);
                    if ($this.data('value') == vx) {
                        $("#attribute_name").text($this.text());
                    }
                });
            }

            $('a[data-type="delete-status"]').click(function () {
                var $tr = $(this).parent().parent();
                alertify.confirm("确定删除此用户？", function (e) {
                    if (e) {
                        var url = "/set/user/delete";
                        var data = "id=" + $tr.attr('data-vid');
                        $.ajax({
                            type: "GET",
                            url: url,
                            data: data,
                            success: function (data) {
                                if (data == "0") {
                                    alertify.alert("操作成功!", function () {
                                        location.reload();
                                    });

                                } else {
                                    alertify.alert("操作失败!");
                                }
                            }
                        });
                    }
                });
            });

            $('a[data-type="edit-status"]').click(function () {
                $this = $(this);
                var $tr = $(this).parent().parent();
                alertify.confirm("确定操作？", function (e) {
                    if (e) {
                        var url = "/set/user/update";
                        var data = "id=" + $tr.attr('data-vid') + "&status=" + $this.attr('data-status');

                        $.ajax({
                            type: "GET",
                            url: url,
                            data: data,
                            success: function (data) {
                                if (data == "0") {
                                    alertify.alert("操作成功!", function () {
                                        location.reload();
                                    });
                                } else {
                                    // alert(data):
                                    // alertify.alert("操作失败!");
                                }
                            }
                        });
                    }
                });
            });
        });
    </script>
</block>